package com.heima.wemedia.feign;

import com.heima.client.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.pojos.wemedia.WmChannel;
import com.heima.model.common.pojos.wemedia.WmUser;
import com.heima.wemedia.mapper.WmUserMapper;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: fly
 * @date: 2024-08-01 14:32
 */

@RestController
public class WemediaClient implements IWemediaClient {

    @Autowired
    private WmUserService userService;
    @Autowired
    private WmUserMapper wmeUserMapper;
    @Autowired
    private WmChannelService wmChannelService;



    /**
     * 创建自媒体端用户
     * @param user
     * @return
     */
    @PostMapping("/api/v1/wmuser")
    public ResponseResult createWmUser(WmUser user) {
        return userService.createWmUser(user);
    }

    /**
     * 获取自媒体用户信息
     *
     * @param id
     * @return
     */
    @Override
    public WmUser getWmUserById(Long id) {
        return wmeUserMapper.selectById(id);
    }

    /**
     * 获取所有频道
     *
     * @return
     */
    @GetMapping("/api/v1/channel/channels")
    public ResponseResult channels() {
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
}
